package com.boss.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.boss.entity.Job;
import com.boss.service.JobService;
import com.boss.util.ResultVOUtil;
import com.boss.vo.JobVo;
import com.boss.vo.ResultVO;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/job")
public class JobController {
    @Resource
    private JobService jobService;
    @GetMapping("/list")
    public ResultVO getJobAll(){
        return ResultVOUtil.success(jobService.getJobAll());
    }
    @GetMapping("/detail")
    public ResultVO getJobById(String id){
        return ResultVOUtil.success(jobService.getJobById(id));
    }
    @GetMapping ("/tabbar")
    public ResultVO  getJobByTab(String name,Integer page,Integer pageSize){
        Page<Job> page1 = new Page<Job>(page, pageSize);
        QueryWrapper<Job> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("classify",name);
        Page<Job> jobPage;
        if(name.equals("全部")){
            jobPage = jobService.page(page1, null);
        }else{
            jobPage = jobService.page(page1, queryWrapper);
        }
        List<Job> records = jobPage.getRecords();
        ArrayList<JobVo> jobVoList = jobService.toJobVoList(records);
        return ResultVOUtil.success(jobVoList);
    }

}
